package com.gitee.wsl.compose.chart.back

import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Paint
import com.gitee.wsl.common.ui.ext.drawLine


/**
 * @ClassName PlotQuadrant
 * @Description 四象限基类
 * @author XiongChuanLiang<br/>(xcl_168@aliyun.com)
 *
 */
class Quadrant() {
    var firstColor = Color.White
    var secondColor = Color.White
    var thirdColor = Color.White
    var fourthColor = Color.White

    var isVisible = false

    var isShowBgColor = true
    var isShowVerticalLine = true
    var isShowHorizontalLine = true

    val bgColorPaint: Paint = Paint()
    val verticalLinePaint: Paint = Paint()
    val horizontalLinePaint: Paint = Paint()

    var quadrantXValue = 0.0f
    var quadrantYValue = 0.0f

    /**
     * 显示象限
     * @param xValue    x轴值
     * @param yValue    y轴值
     */
    fun show(xValue: Float, yValue: Float) {
        setQuadrantXYValue(xValue, yValue)
        isVisible = true
    }

    /**
     * 设置象限中心点的值
     * @param xValue    x方向实际值
     * @param yValue    y方向实际值
     */
    fun setQuadrantXYValue(xValue: Float, yValue: Float) {
        quadrantXValue = xValue
        quadrantYValue = yValue
    }


    /**
     * 设置各个象限的颜色
     * @param first        第一象限
     * @param second    第二象限
     * @param third        第三象限
     * @param fourth    第四象限
     */
    fun setBgColor(first: Color, second: Color, third: Color, fourth: Color) {
        firstColor = first
        secondColor = second
        thirdColor = third
        fourthColor = fourth
    }

    fun renderQuadrant(
        canvas: Canvas,
        centerX: Float, centerY: Float,
        left: Float, top: Float, right: Float, bottom: Float
    ) {
        if (isShowBgColor){ //绘制bg
            bgColorPaint.color = firstColor
            canvas.drawRect(centerX, top, right, centerY, bgColorPaint)
            bgColorPaint.color = secondColor
            canvas.drawRect(centerX, centerY, right, bottom, bgColorPaint)
            bgColorPaint.color = thirdColor
            canvas.drawRect(left, centerY, centerX, bottom, bgColorPaint)
            bgColorPaint.color = fourthColor
            canvas.drawRect(left, top, centerX, centerY, bgColorPaint)
        }
        if (isShowVerticalLine) {
            canvas.drawLine(centerX, top, centerX, bottom, verticalLinePaint)
        }
        if (isShowHorizontalLine) {
            canvas.drawLine(left, centerY, right, centerY, horizontalLinePaint)
        }
    }
}